<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>axios 实例</title>
</head>
<body>
  <h2>axios 实例的创建</h2>
  <button id="btn">发送请求</button>
  <script>
    document.addEventListener('DOMContentLoaded', function () {
      // 创建 axios 实例(可以根据业务场景创建多个实例)
      const instance = axios.create({
        baseURL: '/',   // http://127.0.0.1  公共路径
        timeout: 10000,  // 请求超时时间
        headers: {}  // 请求头
      })

      // 获取节点
      const oBtn = document.querySelector('#btn')
      oBtn.onclick = async () => { 
        try {
          const result = await instance.get('/query', {
            params: {
              id: '001'
            }
          })
          console.log(result)
        } catch (error) {
          console.log(error)
        }
      }
    })
  </script>
  <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
</body>
</html>